package cn.tang.crm.service;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.SQLException;

import org.apache.log4j.PropertyConfigurator;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;

public class CRMServer {

	public static void main(String[] args) throws SQLException {
		new CRMServer().start();
	}

	public void start() throws SQLException {
		URL url = CRMServer.class.getClassLoader().getResource("log4j.properties");
		try {
			if (url == null) {
				String filePath = System.getProperty("user.dir") + File.separator + "log4j.properties";
				System.out.println(filePath);
				url = new File(filePath).toURI().toURL();
			}
		} catch (MalformedURLException e1) {
			e1.printStackTrace();
		}
		PropertyConfigurator.configure(url);

		Server server = new Server(8080);
		WebAppContext webapp = new WebAppContext();
		webapp.setContextPath("/");
		webapp.setWar("./webapp");
		server.setHandler(webapp);
		try {
			server.start();
			server.join();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
